import core.util.validation.Validator;
import core.util.validation.NonEmptyValidator;
import core.util.validation.TextField;

/**
 * Login form validation logic.
 */
class xcms.plugins.auth.LoginFormValidator
	extends core.util.validation.Validator
{
	/**
	 * Initializes the login form validator. 
	 *
	 * @param form (LoginForm) The form to validate.
	 */
	this.LoginFormValidator = function(form) {
		with (core.util.validation) {
			this.username = new NonEmptyValidator(new TextField(form.getUsername()));
			this.password = new NonEmptyValidator(new TextField(form.getPassword()));
		}
	}

	/**
	 * Performs validation. 
	 *
	 * @throws ValidationError When validation fails.
	 */
	this.validate = function() {
		try {
			this.username.validate();
			this.password.validate();
		} catch (e) { // ValidationError
			throw new core.util.validation.ValidationError(this,
				(e.getValidator() == this.username)
					? 'Username field should not be empty.'
					: 'Password field should not be empty.');
		}
	}
}